package quotation.web.formula.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.jexl3.JexlBuilder;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
import org.apache.commons.jexl3.MapContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import quotation.R.R;
import quotation.web.formula.service.FormulaService;

/**
 * @author lyx
 * @date 2025/2/19
 */

@RestController
@RequestMapping("/formula")
@Api(tags = "报价计算公式")
public class FormulaController {

    @Autowired
    private FormulaService formulaService;

    @PostMapping("/add")
    @ApiModelProperty(value = "添加报价计算公式")
    public R add() {

        return R.success("新增成功");
    }

    @DeleteMapping("/delete")
    @ApiModelProperty(value = "删除报价计算公式")
    public R remove() {

        return R.success("删除成功");
    }

    @PutMapping("/update")
    @ApiModelProperty(value = "修改报价计算公式")
    public R update() {

        return R.success("修改成功");
    }

    @GetMapping("/get")
    @ApiModelProperty(value = "获取报价计算公式")
    public R get() {

        return R.success("获取成功");
    }

    public static void main(String[] args) {
        //String expressionString = "总人数+一线生产岗位人员-普通销售岗位人员+客服、后勤保障人员+ljj-dkw";
        String expressionString = "(lyx+ljj)*0.1-dkw%11";
        JexlEngine jexlEngine = new JexlBuilder().create();
        // 定义上下文
        JexlContext context = new MapContext();
        context.set("lyx", 10);
        context.set("ljj", 40);
        context.set("dkw", 50);
        Object evaluate = jexlEngine.createExpression(expressionString).evaluate(context);

        System.out.println(evaluate);
    }
}
